<template>
    <div class="content">
        <div class="login">
            <el-form class="form" ref="formValidate" label-width="60px">
                <el-form-item label="用户名" class="el-form-item">
                    <el-input v-model="form.username" class="input" placeholder="请输入用户名" />
                </el-form-item>
                <el-form-item label="密码" class="el-form-item">
                    <el-input v-model="form.password" class="input" type="password" placeholder="请输入密码" />
                </el-form-item>
                <el-form-item>
                    <div class="submit">
                        <el-button type="primary" size="large" @click="submitForm()">登录</el-button>
                        <el-button @click="resetForm()" size="large">重置</el-button>
                    </div>
                </el-form-item>
            </el-form>

        </div>

    </div>
</template>


<script lang="ts" setup>
import { ref, reactive } from 'vue';
import { login } from "@/api/user"
import router from '@/router';
const form = reactive({
    username: "username",
    password: "password"
})


const submitForm = async () => {

    let result = await login(form)

    const { token, user } = result.data;

    localStorage.setItem("token", token);

    localStorage.setItem("user", user);

    await router.push("/")



}

const addDomain = () => {

}

const resetForm = () => {

}



</script>

<style scoped >
.el-form-item {
    margin: 40px 0;
}

.submit {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 200px;
}

.content {
    background-image: url(@/img/bg.png);
    background-repeat: no-repeat;
    position: fixed;
    background-size: cover;
    left: 0;
    right: 0;
    top: 0;
    width: 100wh;
    height: 100vh;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;

}

.form {
    margin-top: 30px;
}

.input {
    width: 260px;
}

.login {
    box-sizing: border-box;
    padding: 30px 20px;
    width: 400px;
    height: 300px;
    border-radius: 6px;
    background-color: white;

}
</style>